home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / strings / delspcrt.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  1.5 KB  |  55 lines

  1. ;void  delete_spc_right(strg);
  2. ;  char  *strg;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.  
  7. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  8.     ASSUME CS:_TEXT
  9.     PUBLIC _delete_spc_right
  10. _delete_spc_right proc near
  11.     pushf            ;save flags
  12.     push di            ;
  13.     mov  bx,sp        ;bx pts to stack
  14.     cmp  _memory_model,0    ;near or far?
  15.     jle  begin        ;jump if near
  16.     inc  bx            ;else add 2 to BX
  17.     inc  bx            ;
  18. begin:    cmp  _memory_model,2    ;data near or far?
  19.     jb   L0            ;jump if near
  20.     les  di,ss:dword ptr[bx+6] ;ES:DI pts to Strg
  21.     jmp  short L00        ;jump ahead
  22. L0:    mov  ax,ds        ;ES = DS
  23.     mov  es,ax        ;
  24.     mov  di,ss:[bx+6]    ;ES:DI pts to Strg
  25. L00:    mov  bl,1        ;errorcode 1 = null string
  26.     cmp  byte ptr es:[di],0    ;null string?
  27.     jz   L2            ;quit if so
  28.     mov  al,0        ;seek terminating char
  29.     mov  cx,256        ;max string size
  30.     cld            ;direction forward
  31.     repne scasb        ;go find it
  32.     jcxz  L2        ;string too long, quit
  33.     dec  di            ;back to last char of string
  34.     dec  di            ;
  35.     std            ;direction backward
  36.     mov  al,32        ;seek space char
  37.     mov  cx,256        ;whole string
  38.     repe scasb        ;find leftmost adjacent space
  39.     inc  bl            ;errorcode 2 = no spaces found
  40.     jcxz L2            ;quit if none found
  41.     inc  di            ;forward to char after last in strg
  42.     inc  di            ;
  43.     mov  byte ptr es:[di],0    ;set terminating byte
  44. L1:    mov  bl,0        ;0 = spaces found and deleted
  45. L2:    mov  _error_code,bl    ;set _error_code
  46.     pop  di            ;
  47.     popf            ;restore flags
  48.     cmp  _memory_model,0    ;quit
  49.     jle  quit        ;
  50.     db   0CBh        ;RET far
  51. quit:    ret            ;RET near
  52. _delete_spc_right ENDP
  53. _TEXT    ENDS
  54.     END
  55.